package com.sds.sweng.swat.miplatform.ui.design.parts.area.sub;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.requests.CreateRequest;

import com.sds.sweng.swat.miplatform.ui.design.layouts.FlowLayoutEx;
import com.sds.sweng.swat.miplatform.ui.design.models.area.sub.HorizontalSubAreaContainer;

public class HorizontalSubAreaContainerPart extends SubAreaPart {

	public boolean isSelectable() {
		return true;
	}

	protected IFigure createFigure() {
		Figure f = new Figure();
		f.setBackgroundColor(ColorConstants.white);
		f.setOpaque(true);

		((HorizontalSubAreaContainer) getModel()).setWidth(getAreaWidth());

		FlowLayoutEx layout = new FlowLayoutEx();
		layout.setStretchMinorAxis(true);
		layout.setMajorSpacing(0);
		layout.setMinorSpacing(-1);

		f.setLayoutManager(layout);

		((HorizontalSubAreaContainer) getModel()).init();

		return f;
	}

	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new LayoutEditPolicy() {

			protected Command getMoveChildrenCommand(Request request) {
				return null;
			}

			protected Command getCreateCommand(CreateRequest request) {
				return null;
			}

			protected EditPolicy createChildEditPolicy(EditPart child) {
				return new NonResizableEditPolicy();
			}
		});
	}

}
